//接口函数
import service from '@/utils/request'
import mockRequest from '@/utils/mockRequest'

export const reqGetCategoryList = () => {
  //返回promise
  return service({
    method:'get',
    url:'/product/getBaseCategoryList'
  })
}

export const reqGetBannerList = () => {
  return mockRequest({
    method:'get',
    url:'/banner'
  })
}

export const reqGetFloorList = () => {
  return mockRequest({
    method:'get',
    url:'/floor'
  })
}

///api/list  post   返回的GoodListData是对象
export const reqGetGoodListData = (searchParams) => {
  return service.post('/list',searchParams,)
}

// /api/item/{ skuId } get
export const reqGetGoodsDetailInfo = (skuId) => {
  return service({
    url:`/item/${skuId}`,
    method:'get'
  })
}

//添加或更新购物车
export const reqAddOrUpdateShopCart = (skuId,skuNum) => {
  return service({
    method:'post',
    url:`/cart/addToCart/${ skuId }/${ skuNum }`
  })
}

//获取购物车列表
export const reqGetShopCartList = () => {
  return service.get('/cart/cartList');
}

//修改商品选中状态
export function reqUpdateOneIsCheck(skuId,isChecked){
  return service.get(`/cart/checkCart/${skuId}/${isChecked}`);
}

//修改商品全选或全不选
export const reqUpdateAllIsCheck = (isChecked,skuIdList) => {
  return service.post( `/cart/batchCheckCart/${isChecked}`,skuIdList );
}

//删除单个购物车
export const reqDeleteOneCart = (skuId) => {
  return service.delete(`/cart/deleteCart/${skuId}`)
}

//删除多个购物车
export const reqDeleteMoreCart = (skuList) => {
  return service.delete('/cart/batchDeleteCart',{
    data:skuList,
  })
}

//注册
export const reqRegister = (userInfo) => {
  return service.post('/user/passport/register',userInfo)
}

//获取验证码
export const reqGetCode = (phone) => {
  return service.get(`/user/passport/sendCode/${phone}`)
}

//登录
export const reqLogin = (userInfo) => {
  return service.post('/user/passport/login',userInfo)
}

//校验token，获取用户数据(token在请求体携带)
export const reqGetUserInfo = () => {
  return service.get('/user/passport/auth/getUserInfo');
}

//退出登录
export const reqUserLogout = () => {
  return service.get('/user/passport/logout');
}

//获取用户地址
export const reqGetUserAddress = () => {
  return service.get('/user/userAddress/auth/findUserAddressList');
}
//获取交易信息
export const reqGetTradeInfo = () => {
  return service.get('/order/auth/trade');
}

//提交订单
///api/order/auth/submitOrder?tradeNo={tradeNo}
export const reqSubmitOrder = (tradeNo,tradeInfo) => {
  return service.post( `/order/auth/submitOrder?tradeNo=${tradeNo}`,tradeInfo);
}

//获取支付信息
export const reqGetPayInfo = (orderId) => {
  return service.get(`/payment/weixin/createNative/${orderId}`);
}

//获取支付状态
export const reqGetPayState = (orderId) => {
  return service.get(`/payment/weixin/queryPayStatus/${orderId}`);
}

//获取订单列表/api/order/auth/{page}/{limit}
export const reqGetMyOrderList = (page,limit) => {
  return service.get(`/order/auth/${page}/${limit}`);
}
//测试接口方法
// reqGetGoodListData({})